package com.penghaisoft.microwms.materialhand.web.insidewarehouse.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.penghaisoft.microwms.common.dto.RawCountingDto;
import com.penghaisoft.microwms.common.dto.Resp;
import com.penghaisoft.microwms.common.service.BaseService;
import com.penghaisoft.microwms.common.wms.model.RawCountingDifference;
import com.penghaisoft.microwms.common.wms.model.RawCountingRecords;
import com.penghaisoft.microwms.common.wms.model.RawCountingTask;
import com.penghaisoft.microwms.common.wms.model.RawStorageSn;
import com.penghaisoft.microwms.materialhand.web.counting.dao.RawCountingDifferenceMapper;
import com.penghaisoft.microwms.materialhand.web.counting.dao.RawCountingRecordsMapper;
import com.penghaisoft.microwms.materialhand.web.counting.dao.RawCountingTaskMapper;
import com.penghaisoft.microwms.materialhand.web.insidewarehouse.service.IMaterialHandInsideWhService;
import com.penghaisoft.microwms.materialhand.web.storage.dao.RawStorageSnMapper;

/** 
* @ClassName: MaterialHandInsideWhServiceImpl 
* @Description: 手持库内服务
* @author jzh
* @date 2018年5月25日 下午4:50:28  
*/
@Service
public class MaterialHandInsideWhServiceImpl extends BaseService implements IMaterialHandInsideWhService {

	 @Autowired
	 private RawCountingTaskMapper rawCountingTaskMapper;
	 
	 @Autowired
	 private RawStorageSnMapper rawStorageSnMapper;

	 @Autowired
	 private RawCountingRecordsMapper rawCountingRecordsMapper;
	 
	 @Autowired
	 private RawCountingDifferenceMapper rawCountingDifferenceMapper;
	 
	/* @Title: queryRawCountingTask 
	 * @Description: 查询盘点单号是否存在
	 * @author jzh
	 * @date 2018年5月25日 下午4:52:17 
	 */
	@Override
	public List<RawCountingTask> queryRawCountingTask(RawCountingTask rawCountingTask) {
		// TODO Auto-generated method stub
		return rawCountingTaskMapper.queryByAny(rawCountingTask);
	}

	/* @Title: updateRawCountingTask 
	 * @Description: 将盘点任务状态置为盘点中
	 * @author jzh
	 * @date 2018年5月28日 上午10:18:53 
	 */
	@Override
	public Resp updateRawCountingTask(RawCountingTask rawCountingTask) {
		rawCountingTask.setStauts("1");
		Integer updateCnt = rawCountingTaskMapper.update(rawCountingTask);
		if(updateCnt.intValue() == 1){
			return success();
		}else{
			return fail("更改状态失败");
		}
	}

	@Override
	public List<RawCountingTask> queryRawCountingTaskByCode(String countingCode) {
		
		return rawCountingTaskMapper.queryByCountingCode(countingCode);
	}

	/* @Title: querybarcodeExist 
	 * @Description: 根据条码，合同号到rawStorageSn中查询，判断当前条码是否在合同号下
	 * @author jzh
	 * @date 2018年5月29日 上午9:44:59 
	 */
	@Override
	public List<RawStorageSn> querybarcodeExist(RawStorageSn rawStorageSn) {
		
		return rawStorageSnMapper.queryByAny(rawStorageSn);
	}

	/* @Title: createRawCountingRecords 
	 * @Description: 创建盘点记录
	 * @author jzh
	 * @date 2018年5月29日 上午10:27:26 
	 */
	@Override
	public Resp createRawCountingRecords(RawCountingRecords rawCountingRecords) {
		rawCountingRecordsMapper.create(rawCountingRecords);
		return success();
	}

	/* @Title: queryRawCountingRecordsExist 
	 * @Description: 查看这个条码是否已经被盘点了countingCode barcode
	 * @author jzh
	 * @date 2018年5月29日 上午10:47:36 
	 */
	@Override
	public List<RawCountingRecords> queryRawCountingRecordsExist(RawCountingRecords rawCountingRecords) {
		
		return rawCountingRecordsMapper.queryByAny(rawCountingRecords);
	}

	@Override
	public int querCountByCountingCode(String countingCode) {
		RawCountingRecords rawCountingRecords = new RawCountingRecords();
		rawCountingRecords.setCountingCode(countingCode);
		
		return rawCountingRecordsMapper.queryCountAny(rawCountingRecords);
	}

	/* @Title: queryLose 
	 * @Description: 根据盘点单号，合同号 查询盘亏数据
	 * @author jzh
	 * @date 2018年5月30日 上午11:09:39 
	 */
	@Override
	public List<RawStorageSn> queryLose(RawCountingDto rawCountingDto) {
		
		return rawStorageSnMapper.queryLose(rawCountingDto);
	}

	/* @Title: createRawCountingDifference 
	 * @Description: 创建盘点差异 
	 * @author jzh
	 * @date 2018年5月30日 下午1:28:01 
	 */
	@Override
	public Resp createRawCountingDifference(RawCountingDifference rawCountingDifference) {
		rawCountingDifferenceMapper.create(rawCountingDifference);
		return success();
	}

	/* @Title: queryWin 
	 * @Description: 根据盘点单号，合同号 查询盘赢数据
	 * @author jzh
	 * @date 2018年5月30日 下午2:05:59 
	 */
	@Override
	public List<RawCountingRecords> queryWin(RawCountingDto rawCountingDto) {
		// TODO Auto-generated method stub
		return rawCountingRecordsMapper.queryWin(rawCountingDto);
	}

	/* @Title: updateRawCountingTaskFinish 
	 * @Description: 将盘点任务状态置为盘点结束
	 * @author jzh
	 * @date 2018年6月1日 上午10:36:19 
	 */
	@Override
	public Resp updateRawCountingTaskFinish(RawCountingTask rawCountingTask) {
		rawCountingTask.setStauts("2");
		Integer updateCnt = rawCountingTaskMapper.update(rawCountingTask);
		if(updateCnt.intValue() == 1){
			return success();
		}else{
			return fail("更改状态失败");
		}
	}

	/**
	 * @Title findRawStorageSnAbs
	 * @Description 查询库存明细列表（数量取绝对值）
	 * @author luoteng
	 * @date 2018年6月4日:下午5:28:41
	 * @param rawStorageSn
	 * @return List<RawStorageSn>
	 */
	@Override
	public List<RawStorageSn> findRawStorageSnAbs(RawStorageSn rawStorageSn){
		return rawStorageSnMapper.queryByAnyAbs(rawStorageSn);
	}

	@Override
	public Integer updateFlagByCode(RawStorageSn storageSn) {
		return rawStorageSnMapper.updateFlagByCode(storageSn);
	}

	@Override
	public Resp updateRawStorageSnWl(RawStorageSn rawStorageSn) {
		
		Integer updateCnt = rawStorageSnMapper.updateWlByCode(rawStorageSn);
		if(updateCnt.intValue() == 1){
			return success();
		}else{
			return fail("更改状态失败");
		}
	}

	@Override
	public Resp updateRawStorageSn(RawStorageSn rawStorageSn) {
		Integer updateCnt = rawStorageSnMapper.updateBySelect(rawStorageSn);
		if(updateCnt.intValue() == 1){
			return success();
		}else{
			return fail("更改状态失败");
		}
	}

}
